function start_task() {
    // 创建弹出框
    Swal.fire({
        title: '输入促销数据',
        input: 'textarea',
        width: 800,
        inputAttributes: {
            autocapitalize: 'off'
        },
        showCancelButton: true,
        confirmButtonText: '确认',
        cancelButtonText: '取消',
        showLoaderOnConfirm: true,
        preConfirm: (text) => {
            // 处理用户输入的文本
            var tasks = handle_input(text);
            for (var i = 0; i < tasks.length; i++) {
                var task_info = tasks[i];
                create_promo(task_info.promotionName, task_info.mainProductSKU, task_info.subProductSKUs);
            }
        },
        allowOutsideClick: () => !Swal.isLoading()
    });
}

function handle_input(text) {
    // 分割文本为行
    var lines = text.split('\n');

    // 创建结果数组
    var result = [];

    // 处理每一行记录
    for (var i = 0; i < lines.length; i++) {
        var line = lines[i];

        // 分割行为字段
        var fields = line.split(',');

        // 提取促销名称和主商品 SKU
        var promotionName = fields[0];
        var mainProductSKU = fields[1];

        // 提取子商品 SKU
        var subProductSKUs = fields.slice(2);

        // 创建记录对象
        var record = {
            promotionName: promotionName,
            mainProductSKU: mainProductSKU,
            subProductSKUs: subProductSKUs
        };

        // 将记录对象添加到结果数组
        result.push(record);
    }
    return result;
}
function create_promo(promo_name, main_sku, gift_sku) {
    var url = 'https://prom.shop.jd.com/rest/shop/promo/order/new-create';
    var headers = {
        'accept': 'application/json, text/plain, */*',
        'content-type': 'application/json;charset=UTF-8',
    }
    var gift_skus = [];
    for (var i = 0; i < gift_sku.length; i++) {
        gift_skus.push({
            "skuId": gift_sku[i],
            "promoPrice": "1.0",
            "num": "1"
        })
    }
    var data = {
        "masterIds": "",
        "name": promo_name,
        "time": [
            dayjs().format('YYYY-MM-DD HH:mm:ss'),
            dayjs().add(30, 'day').format('YYYY-MM-DD HH:mm:ss')
        ],
        "platForm": [
            1
        ],
        "memberLevel": 1,
        "busiPlatform": {
            "platformName": [
                "全部渠道"
            ],
            "selectType": 0,
            "channelList": [
                1
            ]
        },
        "member": {
            "userClass": "1",
            "userLevel": null,
            "memberLevelName": "京东会员"
        },
        "link": "",
        "areaType": 1,
        "promoAreaType": "",
        "areaVOList": [],
        "stores": [],
        "bindType": 1,
        "giftType": 2,
        "saleOutTotalNum": false,
        "startTime": dayjs().format('YYYY-MM-DD HH:mm:ss'),
        "endTime": dayjs().add(30, 'day').format('YYYY-MM-DD HH:mm:ss'),
        "o2oForm": {
            "form": {
                "storePromo": 1,
                "maxNumForActivityEnable": false,
                "maxNumForUserEnable": false,
                "maxNumForActivity": "",
                "maxNumForUser": "",
                "propagateWords": null
            },
            "storeRange": false,
            "params": {
                "stores": [],
                "storeIds": [],
                "checkName": ""
            }
        },
        "orderModeType": 12,
        "giftClientImgCheckbox": false,
        "giftClientImgRadio": 1,
        "rebateType": 0,
        "bound": 1,
        "wareGrade": "1",
        "priceTrial": 1,
        "orderModes": [
            {
                "giftSkus": gift_skus
            }
        ],
        "skuIds": [
            main_sku
        ],
        "mainSkuList": [
            {
                "skuId": main_sku
            }
        ],
        "busiCode": "orderpromo_12",
        "strategyParam": "",
        "minNum": 1,
        "giftImage": false,
        "scene": "pc"
    }
    GM_xmlhttpRequest({
        url: url,
        method: "POST",
        responseType: "json",
        data: JSON.stringify(data),
        headers: headers,
        onload(resp) {
            var resp_data_str = resp.responseText;
            resp_data = JSON.parse(resp_data_str);
            notify_log(resp_data.success, promo_name, resp_data_str)
        }
    });
}